#include "mybutton.h"
#include <QPainter>
#include "commondef.h"
#include "global/myresource.h"
#include <QDebug>

MyButton::MyButton(QWidget *parent,QSizeF s) :
    BaseBtnWidget                   (parent),
    m_bfouse                        (false),
    m_ifontsize                     (8)
{
    m_size = s;
}

MyButton::~MyButton()
{

}

void MyButton::paintEvent(QPaintEvent *e)
{
    QPainter    p(this);

    switch(m_state)
    {
    case NORMAL_IB:
    {
        p.setPen(QColor(255,255,255));
        p.drawImage(QRectF(QPointF(0.0f,0.0f),m_size),
                    *MyResource::m_buttonpImage,BTN_IMAGE_RECT);
    }
        break;
    case PRESS_IB:
    {
        p.setPen(QColor(146,146,146));
        p.drawImage(QRectF(QPointF(0.0f,0.0f),m_size),
                    *MyResource::m_buttonImage,BTN_IMAGE_RECT);
    }
        break;
    default:
        break;
    }

//    p.setPen(QColor(146,146,146));
    QFont f("Times [Cronyx]",m_ifontsize);//"Times [Cronyx]", "Palatino". "Helvetica [Cronyx]".
    p.setFont(f);

    p.drawText(QRectF(QPointF(0.0f,0.0f),m_size),Qt::AlignCenter,m_textstr);
}

void MyButton::setText(const QString &text,const int size)
{
    m_textstr = text;
    m_ifontsize = size;
}
